/*
 * @Date: 2025-11-07 18:06:16
 * @Auth: 873768511@qq.com
 * @LastEditors: 873768511@qq.com
 * @LastEditTime: 2025-11-11 16:15:29
 * @FilePath: \corpus\src\pages\systemManagement\menu\components\Fields\BasicInfoField\index.tsx
 */
import { Form, Input, Radio } from 'antd';

import hooks from '../../../hooks';

import { JumpWayEnum, MenuTypeEnum } from '@/types/systemManagement/menu';

const BasicInfoField = () => {
  const { form, editingId } = hooks.useContainer();

  return (
    <>
      <Form.Item name="parentId" hidden>
        <Input />
      </Form.Item>
      <Form.Item name="level" hidden>
        <Input />
      </Form.Item>
      <Form.Item noStyle shouldUpdate={(prev, next) => prev?.level !== next?.level}>
        {() => (
          <Form.Item
            name="menuType"
            label="类型"
            dependencies={['parentId']}
            rules={[{ required: true }]}
            initialValue={form.getFieldValue('level') === 5 ? MenuTypeEnum.MENU : MenuTypeEnum.CAT}
          >
            <Radio.Group disabled={!!editingId || form.getFieldValue('level') >= 5}>
              <Radio value={MenuTypeEnum.CAT}>目录</Radio>
              <Radio value={MenuTypeEnum.MENU}>菜单</Radio>
            </Radio.Group>
          </Form.Item>
        )}
      </Form.Item>
      <Form.Item noStyle shouldUpdate={(prev, next) => prev?.parentId !== next?.parentId}>
        {() =>
          !!form.getFieldValue('parentId') ? (
            <Form.Item name="parentMenuName" label="父级菜单">
              <Input disabled />
            </Form.Item>
          ) : null
        }
      </Form.Item>
      <Form.Item name="menuName" label="名称" rules={[{ required: true, message: '请输入名称' }]}>
        <Input placeholder="请输入" maxLength={20} />
      </Form.Item>
      <Form.Item name="url" label="地址" rules={[{ required: true, message: '请输入地址' }]}>
        <Input placeholder="请输入" maxLength={200} />
      </Form.Item>
      <Form.Item noStyle shouldUpdate={(prev, next) => prev.menuType !== next.menuType}>
        {() =>
          form?.getFieldValue('menuType') === MenuTypeEnum.MENU ? (
            <Form.Item name="jumpWay" label="跳转方式" rules={[{ required: true }]}>
              <Radio.Group>
                <Radio value={JumpWayEnum.CURRENT}>当前页面</Radio>
                <Radio value={JumpWayEnum.NEW}>新页面</Radio>
              </Radio.Group>
            </Form.Item>
          ) : null
        }
      </Form.Item>
      <Form.Item name="menuDesc" label="描述">
        <Input.TextArea placeholder="请输入" maxLength={200} />
      </Form.Item>
      <Form.Item
        name="icon"
        label="上传图标"
        tooltip={{
          title: (
            <div>
              从以下图标库中获取图标标识
              <br />
              https://ant-design.antgroup.com/components/icon-cn
            </div>
          ),
          overlayInnerStyle: { width: 380 },
        }}
      >
        <Input placeholder="请输入图标标识" />
      </Form.Item>
    </>
  );
};

export default BasicInfoField;
